package handle;

import common.Constants.ServiceConstant;
import common.Result;
import dataBean.UserDo;
import dataBean.UserInfoDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import service.TokenService;
import service.UserService;
import service.VerifyService;

/**
 * Created by lxl on 2015/11/6.
 */
@Controller
@RequestMapping("ssms/modify")
public class ModifyPasswordHandle {

    @Autowired
    private UserService userService ;

    @Autowired
    private VerifyService verifyService ;

    @Autowired
    private TokenService tokenService ;

    @RequestMapping(value = "/password",method = RequestMethod.POST)
    public @ResponseBody
    Result process( @RequestBody UserDo userDo , @RequestHeader String token ){

        Result result = verifyService.verify(token, ServiceConstant.NO_LEVEL) ;

        if( result.isSucces() ){

            userDo.setUsername(tokenService.getUserName(token));
            result = userService.modifyPassword(userDo,userDo.getOldPassword()) ;

        }

        return  result ;

    }


}
